import 'package:flutter/material.dart';

class FSwitch extends StatelessWidget {
  const FSwitch(
      {super.key,
      required this.value,
      required this.valueChanged,
      this.size = const Size(42, 22),
      this.bgColor = const Color(0xFFCDCDCD),
      this.activeColor = const Color(0xFF00DF6C),
      this.thumbColor = Colors.white});
  final bool value;
  final ValueChanged<bool> valueChanged;
  final Size size;
  final Color bgColor;
  final Color activeColor;
  final Color thumbColor;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () => valueChanged(!value),
      child: AnimatedContainer(
        width: size.width,
        height: size.height,
        duration: const Duration(milliseconds: 200),
        padding: const EdgeInsets.all(2),
        alignment: value ? Alignment.centerRight : Alignment.centerLeft,
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(30),
          color: value ? activeColor : bgColor,
        ),
        child: AspectRatio(aspectRatio: 1, child: AnimatedContainer(duration: const Duration(milliseconds: 200), decoration: BoxDecoration(shape: BoxShape.circle, color: thumbColor))),
      ),
    );
  }
}
